package petword;

import tool.CmdControl;
import tool.CmdControl.Cmd;

/**
 * 宠物小游戏
 */
public class PetWord {
    
    public static void main(String[] args) {
        System.out.println("正在启动宠物小游戏...");
        PetWord petWord = new PetWord();
        petWord.init();
    }
    //键盘控制操作
    private CmdControl control;
    //宠物
    private Pet pet=null;

    /**
     * 创建世界
     */
    public void init()
    {
        System.out.println("游戏加载中...");
        
        //初始化命令
        control = new CmdControl();
        initControlFun();
        System.out.println("游戏加载完成");
        
        //循环监听按键输入
        control.scanCmd();
    }

    private void addPet()
    {
        System.out.println("选中领养宠物类型输入1或者2 1 -- 狗 2 -- 猫");
        boolean run = true;
        while(run)
        {
            String cmd = CmdControl.in();
            if(cmd!=null&&!cmd.isEmpty())
            {
                if(cmd.equals("1"))
                {
                   System.out.println("输入宠物名字");
                   pet = new Dog(CmdControl.in());
                   run = false;
                }

                if(cmd.equals("2"))
                {
                    System.out.println("输入宠物名字");
                    pet = new Cat(CmdControl.in());
                    run = false;
                }
            }

            if(run == true)
            {
                System.out.println("命令错误，重新输入");
            }
        }
    }
    /**
     * 初始化所有的命令信息
     */
    private void initControlFun()
    {
        System.out.println("命令初始化...");
        control.addCmd(new Cmd("run","宠物跑动") {

            @Override
            public void doFun() {
                // TODO Auto-generated method stub
                if(pet==null)
                    System.out.println("当前没有宠物，先领养宠物");
                else
                pet.run();
            }
            
        });
        control.addCmd(new Cmd("add","领养宠物") {

            @Override
            public void doFun() {
                // TODO Auto-generated method stub
                addPet();
            }
            
        });
        control.addCmd(new Cmd("look","查看宠物") {

            @Override
            public void doFun() {
                // TODO Auto-generated method stub
                if(pet==null)
                    System.out.println("当前没有宠物，先领养宠物");
                else
                pet.look();
            }
            
        });
        control.addCmd(new Cmd("eat","宠物进食") {

            @Override
            public void doFun() {
                // TODO Auto-generated method stub
                if(pet==null)
                    System.out.println("当前没有宠物，先领养宠物");
                else
                pet.eat();
            }
            
        });
    }


}
